﻿namespace CardPlay.Model.GameModel.Actions
{
    public class RemovePileAction : PileAction
    {
        public RemovePileAction(CardGame cardGame, PartLocation location) : base(cardGame, location)
        {
            PileBeingRemoved = TopPile;
        }

        public RemovePileAction(CardGame cardGame, PartLocation location, int count) : base(cardGame, location)
        {
            PileBeingRemoved = SourcePile.SubPile(location.Index, location.Index + count);
        }

        public CardPile PileBeingRemoved
        {
            get; private set;
        }

        protected override void OnExecute()
        {
            CardGame.PileAt(Location).RemoveCards(Location.Index, PileBeingRemoved.Count);
        }
        
        protected override void OnReverse()
        {
            CardGame.PileAt(Location).InsertCards(Location.Index, PileBeingRemoved);
        }
    }
}
